﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 观察者模式
{
    //显示未来几天天气的公告牌
    class ForecastDisplay : Observer, DisplayElement
    {
        private WeatherData weatherData;

        private List<float> forecastTemperatures;//未来几天的温度

        public ForecastDisplay(WeatherData weatherData)
        {
            this.weatherData = weatherData;
            this.weatherData.registerObserver(this);
        }


        public void display()
        {
            Console.WriteLine("未来几天的气温");
            int count = forecastTemperatures.Count;
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("第" + i + "天:" + forecastTemperatures[i] + "℃");
            }
        }

        public override void update(string msg)
        {
            forecastTemperatures = weatherData.getForecastTemperatures();
            display();
        }
    }
}
